package com.JaMorant.SSM.thc.listener;

import com.JaMorant.SSM.model.thc.GoodsConfig;
import com.JaMorant.SSM.thc.mapper.GoodsConfigMapper;
import com.JaMorant.SSM.vo.thc.GoodsConfigShiyongVo;
import com.JaMorant.SSM.vo.thc.GoodsConfigVo;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class GoodsConfigShiyongListener extends AnalysisEventListener<GoodsConfigShiyongVo> {

    //注入mapper
    @Autowired
    private GoodsConfigMapper goodsConfigMapper;

    //一行一行，从第二行
    @Override
    public void invoke(GoodsConfigShiyongVo goodsConfigVo, AnalysisContext analysisContext) {
        GoodsConfig chengshi = new GoodsConfig();
        //  DeliveryConfigVo -- Chengshi
        BeanUtils.copyProperties(goodsConfigVo,chengshi);
        if (goodsConfigVo.getGoodsName().contains("纸尿裤好芯好报")){
            BigDecimal bigDecimal = new BigDecimal(19);
            chengshi.setPrice(bigDecimal.multiply(goodsConfigVo.getStock()));
        }  else if (goodsConfigVo.getGoodsName().contains("纸尿裤全芯全意")){
            BigDecimal bigDecimal = new BigDecimal(19.58);
            chengshi.setPrice(bigDecimal.multiply(goodsConfigVo.getStock()));
        }else if (goodsConfigVo.getGoodsName().contains("拉拉裤好芯好报")){
            BigDecimal bigDecimal = new BigDecimal(19);
            chengshi.setPrice(bigDecimal.multiply(goodsConfigVo.getStock()));
        }else if (goodsConfigVo.getGoodsName().contains("拉拉裤全芯全意")){
            BigDecimal bigDecimal = new BigDecimal(19.42);
            chengshi.setPrice(bigDecimal.multiply(goodsConfigVo.getStock()));
        } else{
            System.out.println("error");
        }

        //添加
        goodsConfigMapper.insert(chengshi);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
